#include "processbar.h"

const char *lable = "|/-\\";
char bar[NUM] = {0};

void processbar(int rate)
{
    if(rate < 0 || rate > 100)
        return;

    int len = strlen(lable);
    printf(GREEN"[%-100s][%d%%][%c]\r"NONE,bar,rate,lable[rate%len]); // 没有/n就没有立即刷新，因为显示器模式是行刷新
    fflush(stdout);
    bar[rate++] = con;
    usleep(rate);
    if(rate < Top)
            bar[rate] = RIGHT;

}

void initbar()
{
    memset(bar,'\0',sizeof(bar));
}

/*
// 缓冲区
void processbar(int pro)
{
    int cnt = 0;
    char bar[NUM] = {0};
    memset(bar,'\0',sizeof(bar));
    int len = strlen(lable);

    while(cnt <= Top)
    {
        printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]); // 没有/n就没有立即刷新，因为显示器模式是行刷新
        fflush(stdout);
        bar[cnt++] = con;
        usleep(pro);
        if(cnt < Top)
            bar[cnt] = RIGHT;
    }

    printf("\n");
}
*/

